home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr09 / vstsrc.zip / SATSITE.C < prev    next >
C/C++ Source or Header  |  1995-01-28  |  19KB  |  461 lines

  1. /*
  2.  * %W% %E% %U%  [EXTREL_1.2]
  3.  *
  4.  * VersaTrack orbit calculations are based on those that appear in Dr. Manfred
  5.  * Bester's sattrack program (the Unix(tm) versions 1 and 2).
  6.  *
  7.  * The data from which the maps where generated come from "xsat", an
  8.  * X-Windows program by David A. Curry (N9MSW).
  9.  *
  10.  * Site coordinates come from various sources, including a couple of
  11.  * World Almanacs, and also from both of the programs mentioned above.
  12.  *
  13.  * The following are authors' applicable copyright notices:
  14.  *
  15.  *                                                                               
  16.  * Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.        
  17.  *                                                                           
  18.  * Permission to use, copy, modify, and distribute this software and its      
  19.  * documentation for educational, research and non-profit purposes, without   
  20.  * fee, and without a written agreement is hereby granted, provided that the  
  21.  * above copyright notice and the following three paragraphs appear in all    
  22.  * copies.                                                                    
  23.  *                                                                              
  24.  * Permission to incorporate this software into commercial products may be    
  25.  * obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,     
  26.  * Berkeley, CA 94709, USA.                                                   
  27.  *                                                                             
  28.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,  
  29.  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF    
  30.  * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED   
  31.  * OF THE POSSIBILITY OF SUCH DAMAGE.                                         
  32.  *                                                                             
  33.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT       
  34.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A    
  35.  * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"       
  36.  * BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,  
  37.  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                   
  38.  *                                                                             
  39.  *                                                                             
  40.  * Copyright 1992 by David A. Curry                                            
  41.  *                                                                             
  42.  * Permission to use, copy, modify, distribute, and sell this software and its 
  43.  * documentation for any purpose is hereby granted without fee, provided that  
  44.  * the above copyright notice appear in all copies and that both that copyright
  45.  * notice and this permission notice appear in supporting documentation.  The  
  46.  * author makes no representations about the suitability of this software for  
  47.  * any purpose.  It is provided "as is" without express or implied warranty.   
  48.  *                                                                             
  49.  * David A. Curry, N9MSW                                                       
  50.  * Purdue University                                                           
  51.  * Engineering Computer Network                                                
  52.  * 1285 Electrical Engineering Building                                        
  53.  * West Lafayette, IN 47907                                                    
  54.  * davy@ecn.purdue.edu                                                         
  55.  *                                                                             
  56.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  57.  *
  58.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  59.  * in whole, or in part, for educational, non-profit and non-commercial use
  60.  * only, free of charge or obligation, and without agreement, provided that
  61.  * all copyrights and restrictions noted herein are observed and followed, and
  62.  * additionally, that this and all other copyright notices listed herein
  63.  * appear unaltered in all copies and in all derived work.
  64.  *
  65.  * This notice shall not in any way void or supersede any of the other authors
  66.  * rights or privileges.
  67.  *
  68.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  69.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  70.  * direct, indirect, incidental, or consequential damage, loss of profits or
  71.  * other tangible or intangible losses or benefits, arising out of or related
  72.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  73.  * but not limited to those of merchantablity and fitness for a particular
  74.  * purpose.
  75.  *
  76.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  77.  * sia@bga.com or sia@realtime.com.
  78.  */
  79.  
  80.  
  81. #include <windows.h>
  82. #include <math.h>
  83. #include <stdio.h>
  84. #include <string.h>
  85. #include <stdlib.h>
  86.  
  87. #include "resource.h"
  88. #include "vstdefs.h"
  89. #include "constant.h"
  90. #include "vsttype.h"
  91. #include "vstextrn.h"
  92.  
  93.  
  94. #undef NITEMS
  95. #define NITEMS 13
  96.  
  97. static char *itemp;
  98. static short itemid[NITEMS] = {
  99.     IDC_SI01, IDC_SI02, IDC_SI03, IDC_SI04,
  100.     IDC_SI05, IDC_SI06, IDC_SI07, IDC_SI08,
  101.     IDC_SI09, IDC_SI10, IDC_SI11, IDC_SI12, IDC_SI13
  102. };
  103.  
  104. /*
  105.  * Show current satellite information.
  106.  */
  107.  
  108. void
  109. showSatellite(hwnd, satp)
  110. HWND hwnd;
  111. satellite_t *satp;
  112. {
  113.     mode_t *mp;
  114.     
  115.     if (satp == NULL) {
  116.         usermsg("No Current Satellite");
  117.         return;
  118.     }
  119.  
  120.     itemp = (char *) (LPVOID) LocalAlloc(LMEM_FIXED, 40 * NITEMS);
  121.  
  122.     sprintf(itemp+(0*40),  "%-.28s", satp->s_name);
  123.     if ((mp = satp->s_modep) != NULL) {
  124.         if (mp->alias[0])
  125.             sprintf(itemp+(0*40), "%-.28s (%s)", satp->s_name, mp->alias);
  126.     }    
  127.     itemp[40-1] = 0;
  128.     sprintf(itemp+(1*40),  "%ld", satp->s_satnum);
  129.     sprintf(itemp+(2*40),  "%-18.18s UTC", satp->s_epochstr);
  130.     sprintf(itemp+(3*40),  "%lu", satp->s_elementset);
  131.     sprintf(itemp+(4*40),  "%lf  d", satp->s_inclination);
  132.     sprintf(itemp+(5*40),  "%lf  d", satp->s_raan);
  133.     sprintf(itemp+(6*40),  "%lf", satp->s_eccentricity);
  134.     sprintf(itemp+(7*40),  "%lf  d", satp->s_argperigee);
  135.     sprintf(itemp+(8*40),  "%lf  d", satp->s_meananomaly);
  136.     sprintf(itemp+(9*40), "%-.2lf  r/d",  satp->s_meanmotion);
  137.     sprintf(itemp+(10*40), "%-2.3le  r/d**2",satp->s_decayrate);
  138.     sprintf(itemp+(11*40), "%lu", satp->s_orbitnum);
  139.     if (mp)
  140.         sprintf(itemp+(12*40),"%-.4lf MHZ", mp->beacon * 1.0e-6);
  141.     else
  142.         strcpy(itemp+12*40, "N/A");
  143.  
  144.     DialogBox(NULL, MAKEINTRESOURCE(IDD_SATINFO), hwnd, ShowSatProc);
  145.  
  146.     LocalFree((HANDLE)itemp);
  147. }
  148.  
  149.  
  150. BOOL CALLBACK ShowSatProc(hwnd, message, wParam, lParam)
  151. HWND hwnd;
  152. UINT message;
  153. WPARAM wParam;
  154. LPARAM lParam;
  155. {
  156.     int i;
  157.     POINT *p;
  158.     
  159.     switch (message) {
  160.     case WM_INITDIALOG:
  161.         p = DialogPos(Gwnd, hwnd);
  162.         for (i=0; i<NITEMS; i++)
  163.             SendDlgItemMessage(hwnd, itemid[i], WM_SETTEXT, (WPARAM)0,
  164.                     (LPARAM) itemp+(i*40));
  165.         SetWindowPos(hwnd, 0, (int)p->x, (int)p->y, 0, 0,
  166.             SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
  167.         break;
  168.     case WM_COMMAND:
  169.         if (LOWORD(wParam) == IDOK) {
  170.             EndDialog(hwnd, wParam);
  171.             return TRUE;
  172.         }
  173.         break;
  174.  
  175.     case WM_CTLCOLOREDIT:
  176.         ColorSet(wParam, CBLACK, 8);
  177.         return (BOOL) hDrawBrush[8];
  178.     }
  179.     return FALSE;
  180. }
  181.  
  182. /*
  183.  * List all satellites.
  184.  */
  185. void
  186. listSatellites(hwnd)
  187. HWND hwnd;
  188. {
  189.     register satellite_t **sipp,*sip;
  190.     char buf[80];
  191.     int n;
  192.  
  193.     if (!satInfo) return;
  194.     
  195.     for (n=0,sipp = satInfo; *sipp ; sipp++, n++) {
  196.     sip = *sipp;
  197.     sprintf(buf, "%.48s   (%d)", sip->s_name, sip->s_satnum); 
  198.     sip->s_lbid = (short) SendMessage(hwnd, LB_ADDSTRING, (WPARAM)0,
  199.                                           (LPARAM)buf);
  200.     }
  201.     sprintf(buf, "List of Satellites  ( %d )", n);
  202.     SendDlgItemMessage(GetParent(hwnd), IDC_LISTOFSATS, WM_SETTEXT,
  203.         (WPARAM) 0, (LPARAM) buf);
  204. }
  205.  
  206. /* The following comment is left here for "historical reasons". */
  207. /******************************************************************************/
  208. /*                                                                            */
  209. /*  Title       : readnorad.c                                                 */
  210. /*  Author      : Manfred Bester, DL5KR                                       */
  211. /*  Date        : 19Jun91                                                     */
  212. /*  Last change : 10Mar93                                                     */
  213. /*                                                                            *//*                                                                            */
  214. /*                                                                            */
  215. /*  Data for each satellite consist of three lines in the following format:   */
  216. /*  0        1         2         3         4         5         6         7
  217. /*  1234567890123456789012345678901234567890123456789012345678901234567890    */
  218. /*  XXXXXXXXXXX                                                               */
  219. /*  1 NNNNNU NNNNNAAA NNNNN.NNNNNNNN +.NNNNNNNN +NNNNN-N +NNNNN-N N NNNNN     */
  220. /*  2 NNNNN NNN.NNNN NNN.NNNN NNNNNNN NNN.NNNN NNN.NNNN NN.NNNNNNNNNNNNNN     */
  221. /*                                                                            */
  222. /*  XXXXXXXXXXX                                                               */
  223. /*  1 AAAAAU 00  0  0 BBBBB.BBBBBBBB  .CCCCCCCC  00000-0  00000-0 0  DDDZ     */
  224. /*  2 AAAAA EEE.EEEE FFF.FFFF GGGGGGG HHH.HHHH III.IIII JJ.JJJJJJJJKKKKKZ     */
  225. /*                                                                            */
  226. /*  KEY:                                                                      */
  227. /*                                                                            */
  228. /*  X = Satellite name                                                        */
  229. /*  A = Catalog number                       G = Eccentricity                 */
  230. /*  B = Epoch time                           H = Argument of perigee          */
  231. /*  C = Decay rate                           I = Mean anomaly                 */
  232. /*  D = Number of the element set            J = Mean motion                  */
  233. /*  E = Inclination                          K = Orbit number                 */
  234. /*  F = RAAN                                 Z = Check sum                    */
  235. /*                                                                            */
  236. /*  Line 0 is an eleven-character name. Lines 1 and 2 are the standard        */
  237. /*  two-line orbital element set format identical to that used by NASA and    */
  238. /*  NORAD. The format description is as follows:                              */
  239. /*                                                                            */
  240. /*  Line 0:                                                                   */
  241. /*  Column     Description                                                    */
  242. /*   01-11     Satellite name                                                 */
  243. /*                                                                            */
  244. /*  Line 1:                                                                   */
  245. /*   01-01     Line number of element set                                     */
  246. /*   03-07     Satellite number                                               *//*   08-08     Classification (U = unclassified)                              */
  247. /*   10-11     International designator (last two digits of launch year)      */
  248. /*   12-14     International designator (launch number of the year)           */
  249. /*   15-17     International designator (piece of launch)                     */
  250. /*   19-20     Epoch year (last two digits of year)                           */
  251. /*   21-32     Epoch (Julian day and fractional portion of the day)           */
  252. /*   34-43     First time derivative of the mean motion                       */
  253. /*             or ballistic coefficient (depending on ephemeris type)         */
  254. /*   45-52     Second time derivative of mean motion (decimal point assumed;  */
  255. /*             blank if n/a)                                                  */
  256. /*   54-61     BSTAR drag term if GP4 general perturbation theory was used;   */
  257. /*             otherwise, radiation pressure coefficient (decimal point       */
  258. /*             assumed)                                                       */
  259. /*   63-63     Ephemeris type                                                 */
  260. /*   65-68     Element set number                                             */
  261. /*   69-69     Check sum (modulo 10)                                          */
  262. /*             (letters, blanks, periods, plus sign = 0; minus sign = 1)      */
  263. /*                                                                            */
  264. /*  Line 2:                                                                   */
  265. /*   01-01     Line number of element set                                     */
  266. /*   03-07     Satellite number                                               */
  267. /*   09-16     Inclination [deg]                                              */
  268. /*   18-25     Right Ascension of the ascending node [deg]                    */
  269. /*   27-33     Eccentricity (decimal point assumed)                           */
  270. /*   35-42     Argument of perigee [deg]                                      */
  271. /*   44-51     Mean anomaly [deg]                                             */
  272. /*   53-63     Mean motion [rev/d]                                            */
  273. /*   64-68     Orbit (revolution number) at epoch [rev]                       */
  274. /*   69-69     Check sum (modulo 10)                                          */
  275. /*                                                                            */
  276. /*  All other columns are blank or fixed.                                     */
  277. /*                                                                            */
  278. /*  Copyright 1992, 1993 Manfred Bester, DL5KR --- All Rights Reserved        */
  279. /*                                                                            */
  280. /******************************************************************************/
  281.  
  282. satellite_t *
  283. findSatbyName(char *buf)
  284. {
  285.     int i, h, l, d;
  286.  
  287.     if (!satInfo)
  288.         return NULL;
  289.  
  290.     for (l = 0, h = NSats -1; h >= l; ) {
  291.         i = (h + l) / 2;
  292.         if ((d = cistrcmp(buf, satInfo[i]->s_name)) == 0)
  293.             return satInfo[i];
  294.         if (d > 0)
  295.             l = i+1;
  296.         else
  297.             h = i-1;
  298.     }
  299.     return (satellite_t *) 0;
  300. }
  301.  
  302.  
  303. satellite_t *
  304. findSatbyID(id)
  305. register int id;
  306. {
  307.     if (!satInfo || (id < 0) || (id > NSats))
  308.         return NULL;
  309.         
  310.     return satInfo[id];
  311. }
  312.  
  313. /*
  314.  * Display information about the current site.
  315.  */
  316.  
  317.  
  318. void
  319. showSite(hwnd, sitep)
  320. HWND hwnd;
  321. site_t *sitep;
  322. {
  323.     if ( !sitep ) {
  324.         usermsg("No Site selected.");
  325.         return;
  326.     }
  327.  
  328.     sprintf(tmpbuf, "%-.31s", sitep->c_name);
  329.     tmpbuf[31] = 0;
  330.     sprintf(tmpbuf+40, "%-.39s", sitep->c_locale);
  331.     tmpbuf[79] = 0;
  332.     sprintf(tmpbuf+80, "%-.4f deg %c", fabs(sitep->c_lat * CRD),
  333.         sitep->c_lat < 0.0 ? 'S' : 'N');
  334.     sprintf(tmpbuf+100, "%-.4f deg %c", fabs(sitep->c_lng * CRD),
  335.     sitep->c_lng > 0.0 ? 'W' : 'E');
  336.     sprintf(tmpbuf+120, "%-.0f m Above MSL", sitep->c_alt / CMKM);
  337.     sprintf(tmpbuf+140, "%4.4s  ( %+.1f hrs )", sitep->c_tzname, sitep->c_timezone*24.0);
  338.     
  339.     (void) DialogBox(NULL, MAKEINTRESOURCE(IDD_SITEINFO), hwnd, ShowSiteProc);
  340. }
  341.  
  342.  
  343. BOOL CALLBACK ShowSiteProc(hwnd, message, wParam, lParam)
  344. HWND hwnd;
  345. UINT message;
  346. WPARAM wParam;
  347. LPARAM lParam;
  348. {
  349.     POINT *p;
  350.     static struct a {
  351.         char *str;
  352.         int  id;
  353.     } items[6] = { tmpbuf, IDC_LOCNAME, tmpbuf+40, IDC_LOCSTATE,
  354.         tmpbuf+80, IDC_LOCLAT, tmpbuf+100, IDC_LOCLON,
  355.         tmpbuf+120, IDC_LOCELV, tmpbuf+140, IDC_LOCTZONE,
  356.     };
  357.     int i;
  358.     
  359.     switch(message) {
  360.         case WM_INITDIALOG:
  361.             p = DialogPos(Gwnd, hwnd);
  362.             for (i=0; i<6; i++) 
  363.                 SendDlgItemMessage(hwnd, (int)items[i].id,
  364.                     (UINT)WM_SETTEXT, (WPARAM) 0, (LPARAM) items[i].str );
  365.             SetWindowPos(hwnd, 0, (int)p->x, (int)p->y, 0, 0,
  366.                 SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
  367.             break;
  368.  
  369.         case WM_COMMAND:
  370.             if (LOWORD(wParam) == IDOK)
  371.                 EndDialog(hwnd, wParam);
  372.             return TRUE;
  373.  
  374.         case WM_CTLCOLOREDIT:
  375.             ColorSet(wParam, CBLACK, 8);
  376.             return (BOOL)hDrawBrush[8];
  377.     }
  378.     return FALSE;
  379. }
  380.  
  381. /*
  382.  * List all known cities.
  383.  */
  384. void
  385. listSites(hwnd)
  386. HWND hwnd; 
  387. {
  388.     site_t **cp;
  389.     int n;
  390.  
  391.     if (!siteInfo)
  392.         return;
  393.     for (n=0,cp = siteInfo; *cp ; cp++,n++) {
  394.         sprintf(tmpbuf, "%-.31s, %-.39s", (*cp)->c_name, (*cp)->c_locale);
  395.             (*cp)->c_lbid = SendMessage(hwnd, LB_ADDSTRING,
  396.             (WPARAM)0, (LPARAM)tmpbuf);
  397.     }
  398.     sprintf(tmpbuf,"List of Sites  ( %d )", n);
  399.     SendDlgItemMessage(GetParent(hwnd), IDC_LISTOFSITES, WM_SETTEXT,
  400.         (WPARAM) 0, (LPARAM) tmpbuf);
  401. }
  402.  
  403. site_t *
  404. findSitebyName(cname)
  405. char *cname;
  406. {
  407.     char *cp, *clocale;
  408.     register int h,l,i,d;
  409.  
  410.     if (!siteInfo)
  411.         return NULL;
  412.  
  413.     for (clocale = NULL, cp = cname; *cp; cp++) {
  414.         if (*cp == ',') {
  415.             clocale = cp+1;
  416.             *cp = 0;
  417.             break;
  418.         }
  419.     }
  420.  
  421.     for (l=0, h = NSites -1; h >= l; ) {
  422.         i = (l + h) / 2;
  423.         d = cistrcmp(cname, siteInfo[i]->c_name);
  424.         if (d == 0) {
  425.             if (clocale) {
  426.                    if (clocale && !(d=cistrcmp(clocale, siteInfo[i]->c_locale))) {
  427.                     *(clocale-1) = ',';
  428.                     return siteInfo[i];
  429.                 }
  430.             }
  431.             else
  432.                 return siteInfo[i];
  433.         }
  434.         if (d > 0)
  435.             l = i + 1;
  436.         else
  437.             h = i - 1;
  438.     } while ( l <= h );
  439.  
  440.     if (clocale)
  441.         *(clocale-1) = ',';
  442.  
  443.     return (site_t *)NULL;
  444. }
  445.  
  446. site_t *
  447. findSitebyID(id)
  448. register int id;
  449. {
  450.     register site_t **ci;
  451.  
  452.     if (!siteInfo)
  453.         return NULL;
  454.  
  455.     for (ci = siteInfo; *ci ; ci++)
  456.         if ((*ci)->c_lbid == id)
  457.             return *ci;
  458.  
  459.     return (site_t *) NULL;
  460. }
  461.